package com.lovo.stock.controller;

import com.lovo.stock.bean.count.SaleMonthBean;
import com.lovo.stock.bean.count.SaleTypeBean;
import com.lovo.stock.constant.MessageCode;
import com.lovo.stock.service.ISaleCountService;
import com.lovo.stock.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售统计
 */
@RestController
@RequestMapping("/saleCount")
public class SaleCountController {
    @Autowired
    ISaleCountService saleCountService;

    /**
     * 按类别统计
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping("/queryTypeSaleCount")
    public ResponseResult<List<SaleTypeBean>> queryTypeSaleCount(String startTime, String endTime){
        ResponseResult<List<SaleTypeBean>> responseResult=new ResponseResult<>();
        try {
            responseResult.setData(saleCountService.queryTypeSaleCount(startTime, endTime));
        }catch (Exception e){
            e.printStackTrace();
            responseResult.setMessage(MessageCode.ERROR.message);
            responseResult.setCode(MessageCode.ERROR.code);
        }
        return responseResult;
    }

    /**
     * 按产品统计
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping("/queryProductSaleCount")
    public ResponseResult<List<SaleTypeBean>> queryProductSaleCount(String startTime, String endTime){
        ResponseResult<List<SaleTypeBean>> responseResult=new ResponseResult<>();
        try {
            responseResult.setData(saleCountService.queryProductSaleCount(startTime, endTime));
        }catch (Exception e){
            e.printStackTrace();
            responseResult.setMessage(MessageCode.ERROR.message);
            responseResult.setCode(MessageCode.ERROR.code);
        }
        return responseResult;
    }

    /**
     * 按月份，类别统计
     * @param time
     * @return
     */
    @RequestMapping("/queryTypeSaleCountByMonth")
    public ResponseResult<Map<Integer,List<SaleMonthBean>>> queryTypeSaleCountByMonth(String time){
        ResponseResult<Map<Integer,List<SaleMonthBean>>> responseResult=new ResponseResult<>();
        try {
            responseResult.setData(saleCountService.queryTypeSaleCountByMonth(time));
        }catch (Exception e){
            e.printStackTrace();
            responseResult.setMessage(MessageCode.ERROR.message);
            responseResult.setCode(MessageCode.ERROR.code);
        }
        return responseResult;
    }
}
